package com.xiaotao.learn.algorithm.struct;

public class ListNode {
    public int val;
    public ListNode next;
    public ListNode() {}
    public ListNode(int val) { this.val = val; }
    public ListNode(int val, ListNode next) { this.val = val; this.next = next; }

    public static ListNode parse(int ...input) {
        if(input.length == 0 ) return null;
        ListNode head = new ListNode(input[0]), ret = head;
        for (int i = 1; i < input.length; i++) {
            head.next = new ListNode(input[i]);
            head = head.next;
        }
        return ret;
    }

    public static void dump(ListNode head) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        while (head != null) {
            sb.append(head.val).append(",");
            head = head.next;
        }
        sb.setCharAt(sb.length() - 1, ']');
        System.out.println(sb.toString());
    }
}
